#include "bigobject_C9.h"

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <highgui.h>

#define BLACK_IMAGE "data/black.bmp"
#define WHITE_IMAGE "data/white.bmp"
#define WHITECORNERS_IMAGE "data/whiteCorners.bmp"
#define WHITEROW_IMAGE "data/whiteRow.bmp"
#define WHITEBOX_IMAGE "data/whiteBox.bmp"
#define WHITEROWCOLUMN_IMAGE "data/whiteRowColumn.bmp"
#define WHITECIRCLE_IMAGE "data/whiteCircle.bmp"
#define WHITERECTANGLES_IMAGE "data/whiteRectangles.bmp"
#define WHITEBOX_NOFILL_IMAGE "data/whiteArrow.bmp"
#define GREYBOX_NOFILL_IMAGE "data/greyBoxNoFill.bmp"


#define TH_HIGH 60
#define TH_LOW 40
#define TH_LOWEST 0



int main (int argc, char **argv){
	string waitForKey;
	IplImage* blackImage = cvLoadImage(BLACK_IMAGE,IPL_DEPTH_8U);
	IplImage* blackImage_gs = cvCreateImage(cvGetSize(blackImage), IPL_DEPTH_8U , 1);
	cvCvtColor(blackImage , blackImage_gs, CV_RGB2GRAY);
	IplImage* whiteImage = cvLoadImage(WHITE_IMAGE,IPL_DEPTH_8U); 
	IplImage* whiteImage_gs = cvCreateImage(cvGetSize(whiteImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteImage , whiteImage_gs, CV_RGB2GRAY);
	IplImage* whiteCornersImage = cvLoadImage(WHITECORNERS_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteCornersImage_gs = cvCreateImage(cvGetSize(whiteCornersImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteCornersImage , whiteCornersImage_gs, CV_RGB2GRAY);
	IplImage* whiteRowImage = cvLoadImage(WHITEROW_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteRowImage_gs = cvCreateImage(cvGetSize(whiteRowImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteRowImage , whiteRowImage_gs, CV_RGB2GRAY);
	IplImage* whiteBoxImage = cvLoadImage(WHITEBOX_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteBoxImage_gs = cvCreateImage(cvGetSize(whiteBoxImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteBoxImage , whiteBoxImage_gs, CV_RGB2GRAY);
	IplImage* whiteRowAndColumnImage = cvLoadImage(WHITEROWCOLUMN_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteRowAndColumnImage_gs = cvCreateImage(cvGetSize(whiteRowAndColumnImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteRowAndColumnImage , whiteRowAndColumnImage_gs, CV_RGB2GRAY);
	IplImage* whiteCircleImage = cvLoadImage(WHITECIRCLE_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteCircleImage_gs = cvCreateImage(cvGetSize(whiteCircleImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteCircleImage , whiteCircleImage_gs, CV_RGB2GRAY);
	IplImage* whiteTwoRectanglesImage = cvLoadImage(WHITERECTANGLES_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteTwoRectanglesImage_gs = cvCreateImage(cvGetSize(whiteTwoRectanglesImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteTwoRectanglesImage , whiteTwoRectanglesImage_gs, CV_RGB2GRAY);
	IplImage* whiteBoxNoFillImage = cvLoadImage(WHITEBOX_NOFILL_IMAGE,IPL_DEPTH_8U);
	IplImage* whiteBoxNoFillImage_gs = cvCreateImage(cvGetSize(whiteBoxNoFillImage), IPL_DEPTH_8U , 1);
	cvCvtColor(whiteBoxNoFillImage , whiteBoxNoFillImage_gs, CV_RGB2GRAY);
	IplImage* greyBoxNoFillImage = cvLoadImage(GREYBOX_NOFILL_IMAGE,IPL_DEPTH_8U);
	IplImage* greyBoxNoFillImage_gs = cvCreateImage(cvGetSize(greyBoxNoFillImage), IPL_DEPTH_8U , 1);
	cvCvtColor(greyBoxNoFillImage , greyBoxNoFillImage_gs, CV_RGB2GRAY);
/*************************************** Test 1 ******************************************

checks the function will return false on an all black image.

*****************************************************************************************/
	if( isThereBigObject( blackImage_gs, TH_LOWEST , TH_LOWEST  , WHITE , WHITE ) ) cout << "TEST 1 FAILED" << endl;
	else cout << "TEST 1 PASSED" << endl;
/*************************************** Test 2 ******************************************

checks the function will return true on an all white image and also
on image with few white pixels - true on images with white objects.

*****************************************************************************************/
	if( isThereBigObject( whiteImage_gs, TH_LOWEST , TH_LOWEST  , WHITE , WHITE ) == false ) cout << "TEST 2 FAILED" << endl;
	else if( isThereBigObject( whiteCornersImage_gs, TH_LOWEST , TH_LOWEST  , WHITE , WHITE ) == false ) cout << "TEST 2 FAILED" << endl;
	else cout << "TEST 2 PASSED" << endl;
/*************************************** Test 3 ******************************************

checks the function will return true on an image with white pixels in a row that their 
number exceeds widthThreshold. checks returns false if no such row exists.

*****************************************************************************************/
	if( isThereBigObject( whiteRowImage_gs, TH_LOW , 0  , WHITE , WHITE ) == false ) cout << "TEST 3 FAILED" << endl;
	else if( isThereBigObject( whiteRowImage_gs, TH_HIGH , 0  , WHITE , WHITE ) ) cout << "TEST 3 FAILED" << endl;
	else cout << "TEST 3 PASSED" << endl;
/*************************************** Test 4 ******************************************

checks the function will return true on an image with white pixels in a row that their 
number exceeds widthThreshold & also same thing with column and heightThreshold.
checks returns false if no such row & column exists.

*****************************************************************************************/
	if( isThereBigObject( whiteBoxImage_gs, TH_LOW , TH_LOW  , WHITE , WHITE ) == false ) cout << "TEST 4 FAILED" << endl;
	else if( isThereBigObject( whiteBoxImage_gs, TH_LOW , TH_HIGH  , WHITE , WHITE ) ) cout << "TEST 4 FAILED" << endl;
	else cout << "TEST 4 PASSED" << endl;
/*************************************** Test 5 ******************************************

checks the function will return true on an image with a box of white pixels
thats bigger than [widthThreshold X heightThreshold].
checks returns false if no such object exists.

*****************************************************************************************/
	if( isThereBigObject( whiteBoxImage_gs, TH_LOW , TH_LOW  , WHITE , WHITE ) == false ) cout << "TEST 5 FAILED" << endl;
	else if( isThereBigObject( whiteRowAndColumnImage_gs, TH_LOW , TH_LOW , WHITE , WHITE ) ) cout << "TEST 5 FAILED" << endl;
	else cout << "TEST 5 PASSED" << endl;
/*************************************** Test 6 ******************************************

checks the function will return true on an image with white pixels in a row that their 
number exceeds widthThreshold & also same thing with column and heightThreshold and also
row and column intersects.
checks returns false if no such object exists.

*****************************************************************************************/
	if( isThereBigObject( whiteCircleImage_gs, TH_LOW , TH_LOW  , WHITE , WHITE ) == false ) cout << "TEST 6 FAILED" << endl;
	else if( isThereBigObject( whiteTwoRectanglesImage_gs, TH_LOW , TH_LOW , WHITE , WHITE ) ) cout << "TEST 6 FAILED" << endl;
	else cout << "TEST 6 PASSED" << endl;
/*************************************** Test 7 ******************************************

checks the function will return true on an image with white pixel object that its 
"limiting box" defined by its top-left bottom-right corners exceeds the thresholds.

*****************************************************************************************/
	if( isThereBigObject( whiteBoxNoFillImage_gs, TH_LOW , TH_LOW  , WHITE , WHITE ) == false ) cout << "TEST 7 FAILED" << endl;
	else cout << "TEST 7 PASSED" << endl;
/*************************************** Test 8 ******************************************

checks function also work in range of greyscale.

*****************************************************************************************/
	if( isThereBigObject( greyBoxNoFillImage_gs, TH_LOW , TH_LOW  , BLACK+1 , WHITE-1 ) == false ) cout << "TEST 8 FAILED" << endl;
	else cout << "TEST 8 PASSED" << endl;

	cin >> waitForKey;
}